package com.xxkk.logic;

import com.ebo.synframework.synroom.executor.SynRoomTask;
import com.xxkk.gameCore.enums.PlayerState;
import com.xxkk.gameCore.global.globalServer.ServerManager;
import com.xxkk.net.websocketNetty.BaseMsgHandler;
import com.xxkk.net.websocketNetty.Player;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class LogicMsgHandler extends BaseMsgHandler {
    private final static Logger logger = Logger.getLogger(LogicMsgHandler.class);
    @Autowired
    private ServerManager serverManager;

    @Override
    public void playerDisconnect(Player player) {
        SynRoomTask synRoomTask = new SynRoomTask(player.getLocation()) {
            @Override
            public void processTask() {
                if (serverContext.rmConnectingPlayer(player)) {// 玩家正在连接
                    logger.info("remove connecting player " + player.getPlayerId());
                }
                if (player.getPlayerState() == PlayerState.onLine) {// 玩家已经登陆
                    Player player1 = serverManager.rmPlayer(player, player.getAreaId());
                    if (player1 != null) {
                        logger.info("remove login player roleId:" + player1.getRoleId());
                    }
                }

            }
        };

        synRoomThreadPool.execute(synRoomTask);
    }
}
